{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">代理商名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" lay-verify="required" class="layui-input" value="{$assn['dl_name']}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">手机号码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="phone" lay-verify="required" class="layui-input" value="{$assn['dl_phone']}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">账号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="account" lay-verify="required" class="layui-input"value="{$assn['dl_account']}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">密码：</label>
                            <div class="layui-input-block">
                                <input type="password" name="password" lay-verify="required|pass" class="layui-input" value="{$assn['password']}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">账号余额：</label>
                            <div class="layui-input-block">
                                <input type="text" name="balance" onkeyup="value=value.replace(/\.\d{2,}$/,value.substr(value.indexOf('.'),2))" lay-verify="required"class="layui-input" value="{$assn['dl_balance']}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">商户：</label>
                            <div class="layui-input-block">
                                <select name="assn_user_id" xm-select="select1" xm-select-search="" xm-select-search-type="dl" xm-select-max="10">
                                    {volist name ="shop" id="vo"}
                                    <option value="{$vo.s_id}"{if in_array($vo['s_id'],$assn['num'])}selected{/if}>{$vo.s_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">代理级别：</label>
                            <div class="layui-input-inline">
                                <select name="level" lay-search="" id=""  lay-filter="province">
                                    <option value="1"{if 1==$assn.dl_level}selected{/if}>省级代理</option>
                                    <option value="2"{if 2==$assn.dl_level}selected{/if}>市级代理</option>
                                    <option value="3"{if 3==$assn.dl_level}selected{/if}>区级代理</option>
                                </select>
                            </div>

                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">地区选择：</label>
                            <div class="layui-input-inline">
                                <select name="province" lay-search="" id="province"  lay-filter="province">
                                    {foreach name="province" item="vo"}
                                    <option value="{$vo.district_id}"{if $assn['dl_sheng']==$vo.district_id}selected{/if}>{$vo.district}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <select name="city" lay-search=""  id="city"  lay-filter="city">
                                    {foreach name="city" item="vo"}
                                    <option value="{$vo.district_id}"{if $assn['dl_shi']==$vo.district_id}selected{/if}>{$vo.district}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <div class="layui-input-inline">
                                <select name="district" lay-search=""  id="city"  lay-filter="city">
                                    {foreach name="district" item="vo"}
                                    <option value="{$vo.district_id}"{if $assn['dl_qu']==$vo.district_id}selected{/if}>{$vo.district}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <input type="hidden" value="{$id}" name="id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            username:function(value,item){
                if(!/^[\S]{2,10}$/.test(value)){
                    return '名称必须2到10字符，且不能出现空格';
                }
                var checkResult = "";
                $.ajax({
                    url:"{:url('User/checkName')}",
                    type:'post',
                    data:"username="+value,
                    async: false,//必须同步
                    success:function(res){
                        if(res.code == 100){
                            checkResult = "该名称已存在";
                        }
                    }
                })
                return checkResult;
            },
            pass: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格'],
            // headCrop:[/^[\S]$/,'头像不能为空'],
            // headCrop:function(value,item){
            //     if(value == ""){
            //         return '头像不能为空';
            //     }
            // },
            realname:[/^[\S]{2,10}$/,'真实姓名必须2到10字符，且不能出现空格']

        });
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('update')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('agent/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })

        });
    });
</script>

</body>
</html>
